package club.framework.web.application.sys.role.service.impl;


import club.framework.web.application.sys.role.entity.Role;
import club.framework.web.application.sys.role.mapper.RoleMapper;
import club.framework.web.application.sys.role.service.IRoleService;
import club.framework.web.base.entity.BasePageReqEntity;
import club.framework.web.base.entity.BasePageResultEntity;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;


/**
 * Created by wangg on 2017/9/8.
 */
@Service
public class RoleServiceImpl implements IRoleService {

    @Resource
    private RoleMapper roleMapper;

    @Override
    public Role getObject(Role role) {
        return null;
    }

    @Override
    public Role getObject(int id) {
        return roleMapper.getRoleById(id);
    }

    @Override
    public Role getObject(long uid) {
        return null;
    }

    @Override
    public int save(Role role) {
        Date now  =  new Date();
        role.setUpdateTime(now);
        role.setCreateTime(now);
        return roleMapper.save(role);
    }

    @Override
    public int delete(Role role) {
        return 0;
    }

    @Override
    public int delete(int id) {
        return roleMapper.deleteRoleById(id);
    }

    @Override
    public int delete(long uid) {
        return 0;
    }

    @Override
    public int update(Role role) {
        return 0;
    }

    @Override
    public BasePageResultEntity<Role> queryPage(BasePageReqEntity<Role> basePageReqEntity) {
        BasePageResultEntity<Role> basePageResultEntity = new BasePageResultEntity<>();
        Role role = basePageReqEntity.getObj();
        int totalCount = roleMapper.queryTotalCount(role);
        List<Role> roleList = roleMapper.queryPage(basePageReqEntity);
        basePageResultEntity.setTotal(totalCount);
        basePageResultEntity.setRows(roleList);
        return basePageResultEntity;
    }
}
